

log using isq_requirement.log , replace

* Stata version 16.1
* requires interflex and reghdfe (See note below)
* Do not forget to change directory 
capture mkdir analysis

use cch_isq.dta , clear

preserve
drop if valX == 0 | valX==.

keep if year>1973
collapse (mean) valX valM econidx freedtrade promotepop idealpointdistance agree3un , by(ctyname)

foreach v of varlist promotepop {
gsort -`v' ctyname
gen `v'rank = _n 
drop `v'
}
gsort -valM ctyname
gen Mrank = _n
gsort -valX ctyname
gen Xrank = _n

sort promotepoprank

*keep in 1/30
order ctyname promotepop Xrank freedtrade econidx idealpointdistance agree3un  
export delimited ctyname promotepop Xrank freedtrade econidx idealpointdistance agree3un  using tab1.txt , replace

restore


drop if ccode==255 | ccode==265

local version  5
xtreg lnX c.lnpromote#i.devd i.year gatt_d lngdp if year>1973 , cl(ccode) fe
est store t2_3
di ((1.01^`=_b[0b.devd#c.lnpromote]')-1)*100
di ((1.01^`=_b[1.devd#c.lnpromote]')-1)*100
di (1.01^`=_b[lngdp]'-1)*100
xtreg lnX c.promotecables#i.devd i.year gatt_d lngdp if year>1973 , cl(ccode) fe
est store t2_4
xtreg lnX c.lnpromotepop#i.devd i.year gatt_d lngdp if year>1973 , cl(ccode) fe
est store t2_5

xtreg lnM c.lnpromote#i.devd i.year gatt_d lngdp if year>1973 , cl(ccode) fe
est store t2_6
xtreg lnM c.promotecables#i.devd i.year gatt_d lngdp if year>1973 , cl(ccode) fe
est store t2_7
xtreg lnM c.lnpromotepop#i.devd i.year gatt_d lngdp if year>1973 , cl(ccode) fe
est store t2_8

#delim ;
estout t2_3 t2_4 t2_5 t2_6 t2_7 t2_8 using "analysis/table2_v`version'.txt"   , starlevels(* .1 ** .05 *** .01) cells(b(star fmt(%9.3f)) 
  se(par fmt(%9.3f))) stats(N N_g r2, fmt( %9.0f %9.0f %9.3f) labels(N Countries R2 )) replace drop(*year*) 
  label order(0.devd#c.lnpromote 1.devd#c.lnpromote 0.devd#c.promotecables 1.devd#c.promotecables 0.devd#c.lnpromotepop 1.devd#c.lnpromotepop  lngdp gatt_d  )  ;
#delim cr 


*** POLITICAL SIMILARITY
** promotecab, lnpromote, lnpromotepop
xtreg lnX c.lnpromote c.idealpointdistance i.year  gatt_d lngdp c.polity2  if year>1973& devd==0 , cl(ccode) fe
est store t3_1
xtreg lnX c.lnpromote##(c.idealpointdistance##c.idealpointdistance) i.year gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_2
margins , dydx(lnpromote) at(idealpointdistance=(1.2(.1)4))
marginsplot , addplot(,yline(0) xlabel(1.2(.2)4)) legend(off) title("Average Marginal Effect of Log of Promotion") xtitle("Ideal Point Distance") scheme(s1mono)
graph export analysis/graph1_v`version'.png , as(png) replace

xtreg lnX c.lnpromote c.agree3un i.year gatt_d lngdp c.polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_3
xtreg lnX c.lnpromote##(c.agree3un##c.agree3un) i.year  gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_4
margins , dydx(lnpromote) at(agree3un=(.3(.05).7))
marginsplot , addplot(,yline(0) xlabel(.3(.05).7)) legend(off) title("Average Marginal Effect of Log of Promotion") xtitle("UN Agreement") scheme(s1mono)
graph export analysis/graph2_v`version'.png , as(png) replace

xtreg lnX c.lnpromote i.atopally i.year gatt_d lngdp c.polity2  if year>1973& devd==0 , cl(ccode) fe
est store t3_5
xtreg lnX c.lnpromote##i.atopally i.year gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_6
margins , dydx(lnpromote) at(atopally=( 0 1))


#delim ;
estout t3_1 t3_2 t3_3 t3_4 /*t3_5 t3_6*/ using "analysis/table3_v`version'.txt"   , starlevels(* .1 ** .05 *** .01) cells(b(star fmt(%9.3f)) 
  se(par fmt(%9.3f))) stats(N N_g r2, fmt( %9.0f %9.0f %9.3f) labels(N Countries R2 )) replace drop(*year*) 
  label order(lnpromote idealpointdistance c.idealpointdistance#c.idealpointdistance c.lnpromote#c.idealpointdistance c.lnpromote#c.idealpointdistance#c.idealpointdistance  agree3un c.agree3un#c.agree3un c.lnpromote#c.agree3un c.lnpromote#c.agree3un#c.agree3un   lngdp gatt_d   )  ;
#delim cr

*** MARKET BARRIERS: econidx tariff ntb movecontrol freedtrade
xtreg lnX c.lnpromote econidx i.year  gatt_d lngdp  polity2 if year>1973& devd==0 , cl(ccode) fe
est store t4_1
xtreg lnX c.lnpromote freedtrade i.year  gatt_d lngdp   polity2 if year>1973& devd==0 , cl(ccode) fe
est store t4_2

xtreg lnX c.lnpromote##c.econidx i.year  gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t4_3
margins , dydx(lnpromote) at(econidx=(2(1)8))
marginsplot , addplot(,yline(0)) name(econ1, replace) xtitle("Economic Index") legend(off) title("") scheme(s1mono)
xtreg lnX c.lnpromote##c.freedtrade i.year gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t4_4
margins , dydx(lnpromote) at(freedtrade=(0/10))
marginsplot , addplot(,yline(0)) name(econ2, replace) xtitle("Freedom to Trade") title("") legend(off) scheme(s1mono)

#delim ;
estout t4_1 t4_3 t4_2 t4_4 using "analysis/table4_v`version'.txt"   , starlevels(* .1 ** .05 *** .01) cells(b(star fmt(%9.3f)) 
  se(par fmt(%9.3f))) stats(N N_g r2, fmt( %9.0f %9.0f %9.3f) labels(N Countries R2 )) replace drop(*year*) 
  label order(lnpromote freedtrade lnpromote#freedtrade econidx lnpromote#econidx  lngdp gatt_d   )  ;
#delim cr

graph combine econ1 econ2, title("Marginal effect of trade promotion") ycommon cols(1) scheme(s1mono)
graph export analysis/econsimil_v`version'.png , as(png) replace 

*** Inteflex

*** NOTE: the interflex command with a kernel estimator only works with older versions of reghdfe
*** To get the command to work, change all mentions of reghdfe in interflex.ado to reghdfe3
*** also make sure that the mata function assert_msg() in reghdfe3.ado is uncommented

preserve
tab year , gen(_yr)
keep if year>1973 & devd==0

** ideal point distance
interflex lnX lnpromote idealpointdistance  _yr2 _yr3 _yr4 _yr5 _yr6  gatt_d lngdp polity2   ,  ///
   cutoff(1.6  3) dlabel("Log of promotion") vce(r) xlabel("Ideal point difference") cl(ccode) fe(ccode)
   graph save fig4a.gph , replace
*graph save analysis/fig4a_v4.gph , replace



interflex lnX lnpromote idealpointdistance  _yr2 _yr3 _yr4 _yr5 _yr6  gatt_d lngdp polity2   , vce(r) ///
   type(kernel) dlabel("Log of promotion") xlabel("Ideal point difference") cl(ccode) fe(ccode) bw( 0.9455)
   graph save fig4b.gph , replace

   
interflex lnX lnpromote agree3un  _yr2 _yr3 _yr4 _yr5 _yr6  gatt_d lngdp polity2   ,  ///
   cutoff(.4  .65) dlabel("Log of promotion") vce(r) xlabel("UN voting similarity") cl(ccode) fe(ccode)
   graph save fig4c.gph , replace
   
 interflex lnX lnpromote agree3un _yr2 _yr3 _yr4 _yr5 _yr6  gatt_d lngdp polity2  ,  ///
   type(kernel) dlabel("Log of promotion") xlabel("UN voting similarity") cl(ccode) fe(ccode)  bw(.0638)
   graph save fig4d.gph , replace

 
   graph combine fig4a.gph fig4b.gph fig4c.gph fig4d.gph , scheme(s1mono)
 graph export analysis/fig4_v`version'.png , as(png) replace
  
** economic index
   interflex lnX lnpromote econidx  _yr2 _yr3 _yr4 _yr5 _yr6  gatt_d lngdp polity2 , vce(r) ///
   type(kernel) dlabel("Log of promotion") xlabel("Economic Index") cl(ccode) fe(ccode) bw(2.1039)
graph save analysis/fig5a_v`version'.gph , replace
** freedom to trade
      interflex lnX lnpromote freedtrade  _yr2 _yr3 _yr4 _yr5 _yr6  gatt_d lngdp polity2   , vce(r) ///
   type(kernel) dlabel("Log of promotion") xlabel("Freedom to Trade") cl(ccode) fe(ccode) bw(8.9125)

graph save analysis/fig5b_v`version'.gph , replace

graph combine analysis/fig5a_v`version'.gph analysis/fig5b_v`version'.gph , scheme(s1mono)
graph export analysis/fig5_v`version'.png , as(png) replace

restore






* LAG OF PROMOTION - FOOTNOTE

** lag of log of promotion
xtreg lnX cL.lnpromote##(c.idealpointdistance##c.idealpointdistance) i.year contig comlang_off  col45 lndistw gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_2
margins , dydx(L.lnpromote) at(idealpointdistance=(1.2(.1)4))
marginsplot , addplot(,yline(0)) legend(off) /*title("Average Marginal Effect of Lead Log of Promotion")*/ title("")  xtitle("Ideal Point Distance") scheme(s1mono)
*graph export analysis/graph8_1_v4.png , as(png) replace

xtreg lnX cL.lnpromote c.agree3un i.year contig comlang_off  col45 lndistw gatt_d lngdp c.polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_3
xtreg lnX cL.lnpromote##(c.agree3un##c.agree3un) i.year contig comlang_off  col45 lndistw gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_4
margins , dydx(L.lnpromote) at(agree3un=(.3(.05).7))
marginsplot , addplot(,yline(0)) legend(off) title("") /*title("Average Marginal Effect of Promotion/All cables") */ xtitle("UN Agreement") scheme(s1mono)

**** Imports

xtreg lnM c.lnpromote##c.idealpointdistance i.year contig comlang_off  col45 lndistw gatt_d lngdp polity2 if year>1973& devd==0 , fe cl(ccode) 
est store t3_2
margins , dydx(lnpromote) at(idealpointdistance=(.5(.5)4))
marginsplot , addplot(,yline(0) xlabel(.5(.5)4)) legend(off) title("") xtitle("Ideal Point Distance") name(polimp1 , replace) scheme(s1mono)
 
xtreg lnM c.lnpromote##c.agree3un i.year contig comlang_off  col45 lndistw gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_4
margins , dydx(lnpromote) at(agree3un=(.3(.1).7))
marginsplot , addplot(,yline(0)) legend(off) title("") xtitle("UN Agreement") name(polimp2 , replace) scheme(s1mono)

xtreg lnM c.lnpromote##(c.idealpointdistance##c.idealpointdistance) i.year contig comlang_off  col45 lndistw gatt_d lngdp polity2 if year>1973& devd==0 , fe cl(ccode) 
est store t3_2
margins , dydx(lnpromote) at(idealpointdistance=(.5(.5)4))
marginsplot , addplot(,yline(0) xlabel(.5(.5)4)) legend(off) title("") xtitle("Ideal Point Distance") name(polimp3 , replace) scheme(s1mono)
 
xtreg lnM c.lnpromote##(c.agree3un##c.agree3un) i.year contig comlang_off  col45 lndistw gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_4
margins , dydx(lnpromote) at(agree3un=(.3(.1).7))
marginsplot , addplot(,yline(0)) legend(off) title("") xtitle("UN Agreement") name(polimp4 , replace) scheme(s1mono)

graph combine polimp1 polimp2 polimp3 polimp4 , title("Effect on Imports: Political Dissimilarity") cols(2) scheme(s1mono)
graph export analysis/polimp_v`version'.png , as(png) replace


xtreg lnM c.lnpromote##c.econidx i.year contig comlang_off  col45 lndistw gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t4_3
margins , dydx(lnpromote) at(econidx=(2/8))
marginsplot , addplot(,yline(0)) name(econimp1, replace) xtitle("Economic Index") legend(off) title("") scheme(s1mono)

xtreg lnM c.lnpromote##c.freedtrade i.year contig comlang_off  col45 lndistw gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t4_4
margins , dydx(lnpromote) at(freedtrade=(0/10))
marginsplot , addplot(,yline(0)) name(econimp2, replace) xtitle("Freedom to Trade") title("") legend(off) scheme(s1mono)

graph combine econimp1 econimp2 , title("Effect on Imports: Economic Dissimilarity") cols(1) scheme(s1mono)
graph export analysis/econimp_v`version'.png , as(png) replace
graph close _all


*** ROBUSTNESS

** APPENDIX
*** POLITICAL SIMILARITY - Log promotion

local t = 1

xtreg lnX c.lnpromotepop c.idealpointdistance i.year gatt_d lngdp c.polity2  if year>1973& devd==0 , cl(ccode) fe
est store tA`t'_1
xtreg lnX c.lnpromotepop##(c.idealpointdistance##c.idealpointdistance) i.year gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store tA`t'_2
margins , dydx(lnpromotepop) at(idealpointdistance=(1.2(.1)4))
marginsplot , addplot(,yline(0)) legend(off) title("") xtitle("Ideal Point Distance") name(graphA1_1, replace) scheme(s1mono)

*graph export analysis/graphA3_v4.png , as(png) replace

xtreg lnX c.lnpromotepop c.agree3un i.year  gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store tA`t'_3
xtreg lnX c.lnpromotepop##(c.agree3un##c.agree3un) i.year  gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store tA`t'_4
margins , dydx(lnpromotepop) at(agree3un=(.3(.05).7))
marginsplot , addplot(,yline(0)) legend(off) title("") xtitle("UN Agreement") name(graphA1_2, replace) scheme(s1mono)
*graph export analysis/graphA4_v4.png , as(png) replace

graph combine graphA1_1 graphA1_2, title("Log promotion/pop: Political Dissimilarity") cols(1) scheme(s1mono)
graph export "analysis/graphA3-1.png" , as(png) replace


xtreg lnX c.lnpromotepop i.atopally i.year  gatt_d lngdp polity2  if year>1973& devd==0 , cl(ccode) fe
est store tA`t'_5
xtreg lnX c.lnpromotepop##i.atopally i.year gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store tA`t'_6
margins , dydx(lnpromotepop) at(atopally=( 0 1))


#delim ;
estout tA`t'_1 tA`t'_2 tA`t'_3 tA`t'_4 /*tA`t'_5 tA`t'_6*/ using "analysis/tableA`t'_v`version'.txt"   , starlevels(* .1 ** .05 *** .01) cells(b(star fmt(%9.3f)) 
  se(par fmt(%9.3f))) stats(N N_g r2, fmt( %9.0f %9.0f %9.3f) labels(N Countries R2 )) replace drop(*year*) 
  label order(lnpromotepop idealpointdistance c.idealpointdistance#c.idealpointdistance c.lnpromotepop#c.idealpointdistance c.lnpromotepop#c.idealpointdistance#c.idealpointdistance  agree3un c.agree3un#c.agree3un c.lnpromotepop#c.agree3un c.lnpromotepop#c.agree3un#c.agree3un   lngdp gatt_d  polity2 )  ;
#delim cr

*** MARKET BARRIERS: econidx tariff ntb movecontrol freedtrade

xtreg lnX c.lnpromotepop##c.econidx i.year  gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
margins , dydx(lnpromotepop) at(econidx=(2(.5)8))
marginsplot , addplot(,yline(0)) name(graphA2_1, replace) xtitle("Economic Index") legend(off) title("") scheme(s1mono)
xtreg lnX c.lnpromotepop##c.freedtrade i.year gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
margins , dydx(lnpromotepop) at(freedtrade=(0/10))
marginsplot , addplot(,yline(0)) name(graphA2_2, replace) xtitle("Freedom to Trade") title("") legend(off) scheme(s1mono)

graph combine graphA2_1 graphA2_2, title("Log promotion/pop: Economic Dissimilarity") scheme(s1mono)
graph export "analysis/graphA3-2.png" , as(png) replace 


** Promotion/cables
local t = 2

xtreg lnX c.promotecables c.idealpointdistance i.year gatt_d lngdp c.polity2  if year>1973& devd==0 , cl(ccode) fe
est store tA`t'_1
xtreg lnX c.promotecables##(c.idealpointdistance##c.idealpointdistance) i.year gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store tA`t'_2
margins , dydx(promotecables) at(idealpointdistance=(1.2(.1)4))
marginsplot , addplot(,yline(0)) legend(off) title("") xtitle("Ideal Point Distance") name(graphA3_1, replace) scheme(s1mono)
*graph export analysis/graphA5_v`version'.png , as(png) replace

xtreg lnX c.promotecables c.agree3un i.year gatt_d lngdp c.polity2 if year>1973& devd==0 , cl(ccode) fe
est store tA`t'_3
xtreg lnX c.promotecables##(c.agree3un##c.agree3un) i.year gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store tA`t'_4
margins , dydx(promotecables) at(agree3un=(.3(.05).7))
marginsplot , addplot(,yline(0)) legend(off) title("") xtitle("UN Agreement")  name(graphA3_2, replace) scheme(s1mono)
*graph export analysis/graphA6_v`version'.png , as(png) replace

graph combine graphA3_1 graphA3_2, title("Promotion/Cables: Political Dissimilarity") cols(1) scheme(s1mono)
graph export "analysis/graphA3-3.png" , as(png) replace


xtreg lnX c.promotecables i.atopally i.year gatt_d lngdp c.polity2  if year>1973& devd==0 , cl(ccode) fe
est store tA`t'_5
xtreg lnX c.promotecables##i.atopally i.year gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store tA`t'_6
margins , dydx(promotecables) at(atopally=( 0 1))


#delim ;
estout tA`t'_1 tA`t'_2 tA`t'_3 tA`t'_4 /*tA`t'_5 tA`t'_6*/ using "analysis/tableA`t'_v`version'.txt"   , starlevels(* .1 ** .05 *** .01) cells(b(star fmt(%9.3f)) 
  se(par fmt(%9.3f))) stats(N N_g r2, fmt( %9.0f %9.0f %9.3f) labels(N Countries R2 )) replace drop(*year*) 
  label order(promotecables idealpointdistance c.idealpointdistance#c.idealpointdistance c.promotecables#c.idealpointdistance c.promotecables#c.idealpointdistance#c.idealpointdistance  agree3un c.agree3un#c.agree3un c.promotecables#c.agree3un c.promotecables#c.agree3un#c.agree3un   lngdp gatt_d  polity2 )  ;
#delim cr

*** MARKET BARRIERS: econidx tariff ntb movecontrol freedtrade
	
xtreg lnX c.promotecables##c.econidx i.year  gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
margins , dydx(promotecables) at(econidx=(2(.5)8))
marginsplot , addplot(,yline(0)) name(graphA4_1, replace) xtitle("Economic Index") legend(off) title("") scheme(s1mono)
xtreg lnX c.promotecables##c.freedtrade i.year gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
margins , dydx(promotecables) at(freedtrade=(0/10))
marginsplot , addplot(,yline(0)) name(graphA4_2, replace) xtitle("Freedom to Trade") title("") legend(off) scheme(s1mono)


graph combine graphA4_1 graphA4_2, title("Promotion/Cables: Economic Dissimilarity") scheme(s1mono)
graph export "analysis/graphA3-4.png" , as(png) replace 



* PLACEBO TEST - ALL CABLES

xtreg lnX c.lnall##(c.idealpointdistance##c.idealpointdistance) i.year gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
margins , dydx(lnall) at(idealpointdistance=(1.2(.1)4))
marginsplot , addplot(,yline(0) xlabel(1.2(.2)4)) legend(off)  name(pol1_all, replace)  xtitle("Ideal Point Distance") scheme(s1mono)
*graph export analysis/graph1_v`version'.png , as(png) replace

xtreg lnX c.lnall##(c.agree3un##c.agree3un) i.year  gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_4
margins , dydx(lnall) at(agree3un=(.3(.05).7))
marginsplot , addplot(,yline(0) xlabel(.3(.05).7)) legend(off)  name(pol2_all, replace) xtitle("UN Agreement") scheme(s1mono)

graph combine pol1_all pol2_all, title("Marginal effect of Log of all cables") ycommon cols(1) scheme(s1mono)
graph export "analysis/graphA3-5.png" , as(png) replace 


xtreg lnX c.lnall##c.econidx i.year  gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t4_3
margins , dydx(lnall) at(econidx=(2(1)8))
marginsplot , addplot(,yline(0)) name(econ1_all, replace) xtitle("Economic Index") legend(off) title("") scheme(s1mono)
xtreg lnX c.lnall##c.freedtrade i.year gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t4_4
margins , dydx(lnall) at(freedtrade=(0/10))
marginsplot , addplot(,yline(0)) name(econ2_all, replace) xtitle("Freedom to Trade") title("") legend(off) scheme(s1mono)

graph combine econ1_all econ2_all, title("Marginal effect of Log of all cables") ycommon cols(1) scheme(s1mono)
graph export "analysis/graphA3-6.png" , as(png) replace 

* No communist 
xtreg lnX c.lnall##(c.idealpointdistance##c.idealpointdistance) i.year gatt_d lngdp polity2 if year>1973& devd==0 & communist==0, cl(ccode) fe
margins , dydx(lnall) at(idealpointdistance=(1.2(.1)4))
marginsplot , addplot(,yline(0) xlabel(1.2(.2)4)) legend(off)  name(pol1_all, replace)  xtitle("Ideal Point Distance") scheme(s1mono)
*graph export analysis/graph1_v`version'.png , as(png) replace

xtreg lnX c.lnall##(c.agree3un##c.agree3un) i.year  gatt_d lngdp polity2 if year>1973& devd==0  & communist==0, cl(ccode) fe
est store t3_4
margins , dydx(lnall) at(agree3un=(.3(.05).7))
marginsplot , addplot(,yline(0) xlabel(.3(.05).7)) legend(off)  name(pol2_all, replace) xtitle("UN Agreement") scheme(s1mono)



** EXCLUDING COMMUNIST
** Excluding communist countries
xtreg lnX c.lnpromote##(c.idealpointdistance##c.idealpointdistance) i.year gatt_d lngdp polity2 if year>1973& devd==0 & communist==0 , cl(ccode) fe
margins , dydx(lnpromote) at(idealpointdistance=(.5(.5)3.5))
marginsplot , addplot(,yline(0) xlabel(.5(.5)3.5)) legend(off) title("") xtitle("Ideal Point Distance") name(graphA5_1, replace) scheme(s1mono)
*graph export analysis/graphA5_v4.png , as(png) replace

xtreg lnX c.lnpromote##(c.agree3un##c.agree3un) i.year  gatt_d lngdp polity2 if year>1973& devd==0 & communist==0  , cl(ccode) fe
margins , dydx(lnpromote) at(agree3un=(.3(.05).7))
marginsplot ,  addplot(,yline(0)) legend(off) title("") xtitle("UN Agreement")  name(graphA5_2, replace) scheme(s1mono)
*graph export analysis/graphA6_v4.png , as(png) replace

graph combine graphA5_1 graphA5_2, title("Log of Promotion, excluding communist:""Political Dissimilarity") scheme(s1mono)
graph export "analysis/graphA3-7.png" , as(png) replace

*** MARKET BARRIERS: econidx tariff ntb movecontrol freedtrade

xtreg lnX c.lnpromote##c.econidx i.year  gatt_d lngdp polity2 if year>1973& devd==0 & communist==0 , cl(ccode) fe
margins , dydx(lnpromote) at(econidx=(2(.5)8))
marginsplot , addplot(,yline(0)) name(graphA6_1, replace) xtitle("Economic Index") legend(off) title("") scheme(s1mono)
xtreg lnX c.lnpromote##c.freedtrade i.year gatt_d lngdp polity2 if year>1973& devd==0 & communist==0 , cl(ccode) fe
margins , dydx(lnpromote) at(freedtrade=(0/10))
marginsplot , addplot(,yline(0)) name(graphA6_2, replace) xtitle("Freedom to Trade") title("") legend(off) scheme(s1mono)


graph combine graphA6_1 graphA6_2, title("Log of Promotion, excluding communist:" "Economic Dissimilarity")  ycommon scheme(s1mono)
graph export "analysis/graphA3-8.png" , as(png) replace 


** Lead of log of promotion 
xtreg lnX cF.lnpromote##(c.idealpointdistance##c.idealpointdistance) i.year contig comlang_off  col45 lndistw gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_2
margins , dydx(F.lnpromote) at(idealpointdistance=(1.2(.1)4))
marginsplot , addplot(,yline(0)) legend(off) /*title("Average Marginal Effect of Lead Log of Promotion")*/ title("")  xtitle("Ideal Point Distance") name(graph6_1, replace) scheme(s1mono)
*graph export analysis/graph8_1_v4.png , as(png) replace

xtreg lnX cF.lnpromote c.agree3un i.year contig comlang_off  col45 lndistw gatt_d lngdp c.polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_3
xtreg lnX cF.lnpromote##(c.agree3un##c.agree3un) i.year contig comlang_off  col45 lndistw gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_4
margins , dydx(F.lnpromote) at(agree3un=(.3(.05).7))
marginsplot , addplot(,yline(0)) legend(off) title("") /*title("Average Marginal Effect of Promotion/All cables") */ xtitle("UN Agreement") name(graph6_2, replace) scheme(s1mono)
*graph export analysis/graph8_1_v4.png , as(png) replace

graph combine graph6_1 graph6_2, title("Lead of Log of Promotion: Political Dissimilarity") cols(1) scheme(s1mono)
graph export "analysis/graphA3-9_v`version'.png" , as(png) replace

xtreg lnX cF.lnpromote##c.econidx i.year contig comlang_off  col45 lndistw gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t4_3
margins , dydx(F.lnpromote) at(econidx=(2(.5)8))
marginsplot , addplot(,yline(0)) name(graph7_1, replace) xtitle("Economic Index") legend(off) title("") scheme(s1mono)
xtreg lnX cF.lnpromote##c.freedtrade i.year contig comlang_off  col45 lndistw gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t4_4
margins , dydx(F.lnpromote) at(freedtrade=(0/10))
marginsplot , addplot(,yline(0)) name(graph7_2, replace) xtitle("Freedom to Trade") title("") legend(off) scheme(s1mono)

graph combine graph7_1 graph7_2, title("Lead of Log of Promotion: Economic Dissimilarity") cols(1) ycommon scheme(s1mono)
graph export "analysis/graphA3-10_v`version'.png" , as(png) replace



* WITH OTHER VARIABLES

xtreg lnX c.lnpromote##(c.idealpointdistance##c.idealpointdistance) i.year freedtrade gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_2
margins , dydx(lnpromote) at(idealpointdistance=(1.2(.1)4))
marginsplot , addplot(,yline(0)) legend(off) /*title("Average Marginal Effect of Lead Promotion/All cables")*/ title("")  xtitle("Ideal Point Distance") name(graphA7_1, replace) scheme(s1mono)
*graph export analysis/graph8_1_v4.png , as(png) replace

xtreg lnX c.lnpromote##(c.agree3un##c.agree3un) i.year freedtrade gatt_d lngdp polity2 if year>1973& devd==0 , cl(ccode) fe
est store t3_4
margins , dydx(lnpromote) at(agree3un=(.4(.05).7))
marginsplot , addplot(,yline(0)) legend(off) title("") /*title("Average Marginal Effect of Promotion/All cables") */ xtitle("UN Agreement") name(graphA7_2, replace) scheme(s1mono)

graph combine graphA7_1 graphA7_2, title("Political similarity, with Freedom to Trade included")  scheme(s1mono)
*graph export analysis/graphA7_v`version'.png , as(png) replace 


xtreg lnX c.lnpromote##c.econidx i.year idealpointdistance gatt_d lngdp polity2 if year>1973& devd==0 & communist==0 , cl(ccode) fe
margins , dydx(lnpromote) at(econidx=(2(.5)8))
marginsplot , addplot(,yline(0)) name(graphA8_1, replace) xtitle("Economic Index") legend(off) title("") scheme(s1mono)
xtreg lnX c.lnpromote##c.freedtrade i.year idealpointdistance gatt_d lngdp polity2 if year>1973& devd==0 & communist==0 , cl(ccode) fe
margins , dydx(lnpromote) at(freedtrade=(0/10))
marginsplot , addplot(,yline(0)) name(graphA8_2, replace) xtitle("Freedom to Trade") title("") legend(off) scheme(s1mono)
graph combine graphA8_1 graphA8_2, title("Economic openness, with Ideal Point Distance included") scheme(s1mono)
*graph export analysis/graphA8_v`version'.png , as(png) replace 


log close
